﻿using Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Win.BLL;
using Win.Model;

namespace ShiYan3
{
    public partial class ManegerForm : Form
    {
        private ManegerBLL manegerBLL = new ManegerBLL();

        public ManegerForm()
        {
            InitializeComponent();
        }

        private void Maneger_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = manegerBLL.GetManagerInfoList();
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "用户名";
            dataGridView1.Columns[2].HeaderText = "密码";
            dataGridView1.Columns[3].HeaderText = "种类";
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                DataGridViewRow row = dataGridView1.Rows[i];
                if (row.Cells["MType"].Value.ToString() == "1")
                {
                    row.Cells["MType"].Value = string.Format("{0}", "店员");
                }
                else
                {
                    row.Cells["MType"].Value = string.Format("{0}", "经理");
                }
            }
        }

        private void button_add_Click(object sender, EventArgs e)
        {
            string username = textBox_username.Text;
            string passwd = Md5Helper.GetMd5(textBox_pw.Text);
            int manager_type;
            if (radioButton_dy.Checked)
            {
                manager_type = 0;
            }
            else
            {
                manager_type = 1;
            }
            ManagerInfo manager = new ManagerInfo(username, passwd, manager_type.ToString());
            manegerBLL.AddManager(manager);
            dataGridView1.DataSource = manegerBLL.GetManagerInfoList();
        }

        private void button_cencel_Click(object sender, EventArgs e)
        {
            textBox_pw.Text = "";
            textBox_username.Text = "";
        }

        private void button_del_Click(object sender, EventArgs e)
        {
            int i = dataGridView1.CurrentRow.Index;
            int id = int.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
            manegerBLL.DeleteManagerById(id);
            dataGridView1.DataSource = manegerBLL.GetManagerInfoList();
        }
    }
}
